﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJP;

namespace RoutingService
{
    public class Configuration
    {
        private const string PrefixServerConfiguration = "server";
        private const string KeyServiceName = PrefixServerConfiguration + ".serviceName";
        private const string KeyServiceDisplayName = PrefixServerConfiguration + ".serviceDisplayName";
        private const string KeyServiceDescription = PrefixServerConfiguration + ".serviceDescription";

        private const string DefaultServiceName = "Spider";
        private const string DefaultServiceDisplayName = "Spider";
        private const string DefaultServiceDescription = "Spider";

        /// <summary>
        /// 服务名称
        /// </summary>
        public static string ServiceName
        {
            get { return GetSetting(KeyServiceName, DefaultServiceName); }
        }

        /// <summary>
        /// 服务显示名称
        /// </summary>
        public static string ServiceDisplayName
        {
            get { return GetSetting(KeyServiceDisplayName, DefaultServiceDisplayName); }
        }

        /// <summary>
        /// 服务描述
        /// </summary>
        public static string ServiceDescription
        {
            get { return GetSetting(KeyServiceDescription, DefaultServiceDescription); }
        }

        /// <summary>
        /// 获取App.config配置信息
        /// </summary>
        /// <param name="key">键值</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        static string GetSetting(string key, string defaultValue = "")
        {
            var value = ConfigurationManager.AppSettings[key];
            if (value.IsNullOrEmpty())
                return defaultValue;
            else
                return value;
        }
    }
}
